package d0906;
import java.text.SimpleDateFormat;
import java.util.*;

public class Calendar类 {
    public static void main(String[] args) {

        // 当前时间的日历对象
        Calendar cal = Calendar.getInstance();
        // 返回 日期对象 Date
        Date date = cal.getTime();
        long time = date.getTime();  // 对比2个类型的 getTime();

        System.out.println("日历对象的时间戳:" + cal.getTime().getTime());
        System.out.println("日历对象的时间戳:" + cal.getTimeInMillis());

        // 设置时间字段值
        cal.set(Calendar.YEAR, 2023);
        cal.set(Calendar.MONTH, 11);
        cal.set(Calendar.DAY_OF_WEEK, 1);

        // 获取字段值
        System.out.println("年:" + cal.get(Calendar.YEAR));
        System.out.println("月:" + cal.get(Calendar.MONTH));
        System.out.println("周几:" + cal.get(Calendar.DAY_OF_WEEK));
        System.out.println("一年中的第几周:" + cal.get(Calendar.WEEK_OF_YEAR));

        // 时间计算
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        System.out.println(sdf.format(cal.getTime()));

        cal.add(Calendar.DAY_OF_MONTH, 1);
        System.out.println(sdf.format(cal.getTime()));

        cal.roll(Calendar.DAY_OF_MONTH, 1);
        System.out.println(sdf.format(cal.getTime()));

        cal.add(Calendar.DAY_OF_MONTH, 30);
        System.out.println(sdf.format(cal.getTime()));

        cal.roll(Calendar.DAY_OF_MONTH, 30);
        System.out.println(sdf.format(cal.getTime()));

        // add 会进位,  roll 不进位

        // 计算今年寒假放假日(2023.1.5)是 星期几 ?  距离放假日的天数?

    }
}
